package qst.com.bacK.mapper;

import org.apache.ibatis.annotations.*;
import qst.com.bacK.pojo.entity.Exam;
import qst.com.bacK.pojo.entity.Schedule;

import java.sql.SQLException;
import java.util.List;

/**
 * Author:   msh
 * Date:     2024/10/10 上午10:52
 * Description:
 */
public interface ScheduleMapper {

    @Select("select * from mbti.schedules where team_id = #{teamId} order by id desc")
    List<Schedule> findByTeamId(int teamId);

    @Select("select * from mbti.schedules where id = #{scheduleId}")
    Schedule findById(@Param("scheduleId") Integer scheduleId) throws SQLException;

    @Select("select * from mbti.exams where schedule_id = #{scheduleId}" +
            " and personnel_id = #{testPersonnelId}")
    Exam findByTestPersonnelAndSchedule(@Param("testPersonnelId") Integer testPersonnelId,
                                        @Param("scheduleId") Integer scheduleId) throws SQLException;

    @Delete("delete from mbti.schedules where id = #{id}")
    void delete(Integer id);

    @Select("select * from mbti.schedules where creator_id = #{id} order by team_id,assessment_id")
    List<Schedule> findByCreatorId(Integer id);

    @Insert("insert into mbti.schedules(begin_date,end_date,duration,create_date,status,creator_id,assessment_id,team_id,question_number) " +
            "values(#{beginDate}, #{endDate}, #{duration}, #{createDate}, #{status}, #{creatorId}, #{assessmentId}, #{teamId}, #{questionNumber})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int save(Schedule schedule) throws SQLException;

    @Update("update mbti.schedules set begin_date = #{beginDate},end_date = #{endDate},duration = #{duration}," +
            "status = #{status},create_date = #{createDate},assessment_id = #{assessmentId},team_id = #{teamId}," +
            "question_number = #{questionNumber} where id = #{id}")
    int update(Schedule schedule) throws SQLException;
}
